﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using WheelClean2.Model;
using WheelClean2.Mould;

namespace WheelClean2.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        private string _title = "轮对激光系统";
        private readonly IDialogService _dialog;
        private readonly IRegionManager _regionManager;
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }

        private List<Track> _tracks;
        /// <summary>
        /// 轨迹
        /// </summary>
        public List<Track> Tracks
        {
            get { return _tracks; }
            set { SetProperty(ref _tracks, value); }
        }

        public DelegateCommand<string> DelegateCommand_Open { get; private set; }

        public DelegateCommand<string> DelegateCommand_Dialog { get; private set; }


        public MainWindowViewModel(IRegionManager contentRegion, IDialogService dialog)
        {
            _regionManager = contentRegion;
            _dialog = dialog;
            DelegateCommand_Open = new DelegateCommand<string>(Open);
            DelegateCommand_Dialog = new DelegateCommand<string>(DialogOpen); ;
            ModbusTCP.Init("192.168.1.88");
            ModbusTCP.Connect();
            ModbusTCP.GetPLCDevices();
            //达标板卡控制初始化
            DaBiaoHelper.Instance.MultiInit();

            //ModbusTCP modbusTCP = new ModbusTCP("192.168.1.88");
            //modbusTCP.Connect();
            //modbusTCP.WriteSingleRegister(23288, 200);
            //modbusTCP.WriteFloat(23288, (float)10.05);
            //var hold2 = modbusTCP.ReadHoldingRegisters(24388,1);//报警位
            //var hold1= modbusTCP.ReadFloat(23288); 
            //var hold= modbusTCP.ReadCoils(12788, 2);
            //AccessDataBase accessDataBase = new AccessDataBase();
            //accessDataBase.Read();


        }

        private void DialogOpen(string obj)
        {
            if (!string.IsNullOrEmpty(obj))
            {
                DialogParameters parameters = new DialogParameters();
                parameters.Add("type", obj);
                // 导航到 ContentRegion 中指定的视图
                _dialog.ShowDialog("AlarmDialog", parameters, null);

            }
        }

        private void Open(string obj)
        {
            // viewName 可能是 "HomeView", "SettingsView", "AboutView" 等
            if (!string.IsNullOrEmpty(obj))
            {
                // 导航到 ContentRegion 中指定的视图
                _regionManager.RequestNavigate("ContentRegion", obj);
            }
        }
    }
}
